package com.itcast.database.smooth.service;

import com.itcast.database.smooth.entity.TradeOrder;
import com.itcast.database.smooth.repository.TradeOrderRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>Description: </p>
 * @date 
 * @author 
 * @version 1.0
 * <p>Copyright:Copyright(c)2020</p>
 */
@Service
public class TradeOrderServiceImpl implements ITradeOrderService {

    @Autowired
    private TradeOrderRepository tradeOrderRepository;


    /**
     * 创建订单
     * @param accountNo
     * @param execPrice
     */
    @Override
    public Long addOrder(Long accountNo, Long execPrice) {
        TradeOrder order = new TradeOrder();
        order.setAccountNo(accountNo);
        order.setExecPrice(execPrice);
        order.setExecTime(new Date());
        TradeOrder orderDB = tradeOrderRepository.save(order);
        return orderDB.getId();
    }

    /**
     * 根据账户编号获取所有订单
     * @return
     */
    @Override
    public List<TradeOrder> findAllByAccountNo(Long accountNo) {
        return tradeOrderRepository.findAllByAccountNo(accountNo);
    }


    /**
     * 获取所有订单
     * @return
     */
    @Override
    public List<TradeOrder> getAllOrders() {
        return tradeOrderRepository.findAll();
    }
}
